package com.yf.controller.api.im;

import com.yf.annotation.LoginUser;
import com.yf.entity.UserEntity;
import com.yf.response.R;
import com.yf.service.*;
import com.yf.service.im.FriendService;
import com.yf.service.im.MsgGroupService;
import com.yf.service.im.MsgService;
import com.yf.service.im.MsgSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.yf.response.R.ok;

/**
 * User: hyh
 * Date: 2018-09-10
 * Time: 9:26
 * Description:
 */
@RequestMapping("/api/msg/center")
@RestController
public class ApiMsgCenterController {


    @Autowired
    private MsgGroupService msgGroupService;

    @Autowired
    private MsgService msgService;

    @Autowired
    private UserService userService;

    @Autowired
    private MsgSessionService msgSessionService;

    @Autowired
    private FriendService friendService;


    /**
     * 获取所有人的会话记录
     *
     * @param userEntity
     * @return
     */
    @GetMapping("/session")
    public R session(@LoginUser UserEntity userEntity) {
        return  R.ok(msgSessionService.getAllMsgSession(userEntity));
    }

    /**
     * 获取自己跟某人的聊天 验证关系
     *
     * @param userEntity
     * @param
     * @return
     */
    @GetMapping("/msg")
    public R msg(Long sessionId,Integer chatType,Long firstMsgTime,Integer limit,@LoginUser UserEntity userEntity){
        return R.ok(msgService.getFriendMsg(userEntity,sessionId,chatType,firstMsgTime,limit));
    }

    /**
     * 返回某人的名字 头像 简介等信息
     *
     * @param userIds
     * @return
     */
    @PostMapping("/userInfo")
    public R userInfo(Long[] userIds) {
        return ok(userService.getUserInfoList(userIds));
    }

    /**
     * 查询群信息
     *
     * @param groupIds
     * @return
     */
    @PostMapping("/groupInfo")
    public R msgGroupInfo(Long[] groupIds) {

        return ok(msgGroupService.getMsgGroupList(groupIds));
    }


//    /**
//     * @Description:加群后查询群主所有的聊天记录（讲课）
//     * @author hyh
//     * @Date 11:52 2018/9/18 0010
//     * @Param
//     * @return
//     */
//    @IgnoreAuth
//    @PostMapping("/msgRecord/groupOwner")
//    public R getAllGroupMsg(Long groupId){
//        return R.ok(msgGroupService.getAllGroupMsg(groupId));
//    }
//
//    /**
//     * 找出某个人的消息聊天记录 分页处理 TODO
//     * {'{chatUserId}':MsgRecordVo}
//     * @param userEntity
//     * @return
//     */
//    @GetMapping("/msgRecord")
//    public R msgRecord(@LoginUser UserEntity userEntity){
//        return R.ok(msgService.getMsgRecord(userEntity.getId()));
//    }


}
